<!-- 完善公司资料 -->
<template>
	<view>
		<view style="background-color: #fff;padding: 20rpx 50rpx;">
			<view class="fs-34">
				完善品牌信息
			</view>
			<view class="marginTop-20">
				丰富的公司介绍，能获得更多的模特的青睐，为你的职位带来更多查看与沟通
			</view>
		</view>
		<view class="marginTop-20">
			<fui-list>
				<fui-list-cell :highlight="false">
					<view class="row-between flex-1">
						<view>品牌Logo</view>
						<view class="">
							<fui-upload :url="uploadUrl" :fileList="CompanyLogos" max="1" radius="5" width="120"
								height="120" @error="uploadError" @complete="uploadComplete($event, 1)"
								Right></fui-upload>
						</view>
					</view>
				</fui-list-cell>

				<fui-list-cell :highlight="false" marginTop="10">
					<view class="row-between flex-1">
						<view>品牌公司全称</view>
						<fui-input inputBorder size="26" placeholder="请填写品牌公司全称" textAlign="right" padding="20rpx"
							v-model="formData.CompanyAllName"></fui-input>
					</view>
				</fui-list-cell>

				<fui-list-cell :highlight="false" marginTop="10">
					<view class="row-between flex-1">
						<view>企业法人</view>
						<fui-input inputBorder size="26" placeholder="请填写企业法人姓名" textAlign="right" padding="20rpx"
							v-model="formData.LegalPerson"></fui-input>
					</view>
				</fui-list-cell>

				<fui-list-cell :highlight="false" marginTop="10" @click="showBirthday">
					<view class="row-between flex-1">
						<view>成立时间</view>
						<fui-input inputBorder size="26" placeholder="请填写企业成立时间" disabled textAlign="right"
							padding="20rpx" v-model="formData.ComRegdate"></fui-input>
					</view>
				</fui-list-cell>
				<fui-list-cell :highlight="false" marginTop="10">
					<view class="row-between flex-1">
						<view>注册地址</view>
						<fui-input inputBorder size="26" placeholder="请填写注册地址" textAlign="right" padding="20rpx"
							v-model="formData.CompanyAddress"></fui-input>
					</view>
				</fui-list-cell>

				<fui-list-cell :highlight="false" marginTop="10">
					<view class="flex-1">
						<view>公司介绍</view>
						<view class="marginTop-10"></view>
						<fui-textarea textareaBorder size="26" isCounter placeholder="请填写企业介绍" maxlength="1000"
							v-model="formData.CompanyMemo"></fui-textarea>
					</view>
				</fui-list-cell>

				<fui-list-cell :highlight="false" marginTop="10">
					<view class="flex-1">
						<view>公司照片</view>
						<view class="marginTop-10"></view>
						<fui-upload max="10" :url="uploadUrl" :fileList="formData.CompanyPics" radius="5" width="200"
							height="150" ref="bgPicUpload" @success="bgPicUpSuccess" @error="uploadError"
							@complete="uploadComplete($event, 2)" Right></fui-upload>
					</view>
				</fui-list-cell>
			</fui-list>
		</view>
		<view style="height: 100rpx;"></view>
		<fui-date-picker :show="birthdayShow" type="3" minDate="1940-01-01" value="1990-01-01" @change="changeBirthday"
			@cancel="cancel('birthday')"></fui-date-picker>

		<view class="fixed left right" style="bottom: 20rpx;z-index: 99;">
			<button class="sub-btn" @click="onSubmit">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uploadUrl: 'https://api.meimo.comdns.cn/common/Upload/upload?file=uniapp&type=image',
				fileList: [],
				birthdayShow: false,
				formData: {
					CompanyName: '',
					CompanyAllName: '', // 公司全称
					CompanyLogo: '', //logo图片
					CompanyPics: [], // 公司图片
					ComRegdate: '', //成立时间
					LegalPerson: '', // 法人
					CompanyMemo: '', // 介绍	
					CompanyAddress: '', // 注册地址
				},
				logoImage: '',
				CompanyPicsImages: [],
				CompanyLogos: [],
			}
		},
		onLoad() {
			this.getCompanData()
		},
		methods: {
			// 获取企业数据
			getCompanData() {
				this.$httpost('/UserCenter/myCompanyInfo', {}).then(res => {
					if (res.code == 200) {
						// console.log('企业数据', res)
						this.formData = res.data;
						this.formData.CompanyPics = JSON.parse(res.data.CompanyPics);
						this.CompanyLogos = [res.data.CompanyLogo];
					}
				})
			},
			// 提交企业数据
			onSubmit() {
				this.formData.CompanyName = this.formData.CompanyAllName;
				this.formData.CompanyLogo = this.CompanyLogos[0];

				if (!this.formData.CompanyLogo) {
					uni.showToast({
						title: '请上传品牌Logo！',
						icon: 'none'
					})
					return false;
				}

				if (this.formData.LegalPerson == '') {
					uni.showToast({
						title: '请填写企业法人！',
						icon: 'none'
					})
					return false;
				}

				if (this.formData.CompanyAllName == '') {
					uni.showToast({
						title: '请填写公司全称！',
						icon: 'none'
					})
					return false;
				}


				if (this.formData.ComRegdate == '') {
					uni.showToast({
						title: '请填写企业法人！',
						icon: 'none'
					})
					return false;
				}

				// console.log('this.formData', this.formData)

				this.$httpost('/Form/CompanySubmit', this.formData).then(res => {
					if (res.code == 200) {
						// console.log('企业数据提交成功', res)
						uni.showToast({
							title: '提交成功',
							icon: 'success'
						})

						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					}
				})
				// console.log('提交成功！')
			},
			// 上传图片结果
			uploadComplete(e, uploadType) {
				// console.log('图片上传', e)
				// 图片上传
				if (e.action == "choose") {
					e.urls.forEach(async (item, index) => {
						if (uploadType == 1) this.CompanyLogos.push(await this.uploadImage(item));
						uni.hideLoading()
						if (uploadType == 2) this.formData.CompanyPics.push(await this.uploadImage(item));
						uni.hideLoading()
					})
				}

				if (e.action == "delete") {
					// console.log('执行了')
					if (uploadType == 1) {
						this.formData.CompanyLogo = '';
						this.CompanyLogos = [];
					}
					if (uploadType == 2) {
						this.formData.CompanyPics = e.urls;
					}
				}
			},
			// 图片上传
			uploadImage(tmpFile) {
				uni.showLoading({
					title: '上传中'
				})
				return new Promise((reslove, reject) => {
					uni.uploadFile({
						url: 'https://api.meimo.comdns.cn/common/Upload/upload?file=uniapp&type=image', //仅为示例，非真实的接口地址
						filePath: tmpFile,
						name: "file",
						formData: {},
						success: (uploadFileRes) => {
							reslove(this.$baseUrl + JSON.parse(uploadFileRes.data).fileName)
						}
					})
				})
			},
			showBirthday() {
				this.birthdayShow = true
			},
			changeBirthday(e) {
				// console.log(e)
				this.formData.ComRegdate = e.result;
				this.birthdayShow = false
			},
			cancel(type) {
				if (type == 'birthday') {
					this.birthdayShow = false
				}
			},
		},
	}
</script>

<style lang="scss">
	.flex-1 {
		flex: 1;
	}

	.fui-input__border.data-v-21633bf6 {
		border: none;
	}
</style>